package com.alan.service.impl;

import com.alan.constants.SystemConstants;
import com.alan.domain.ResponseResult;
import com.alan.domain.entity.Link;
import com.alan.domain.vo.LinkVo;
import com.alan.mapper.LinkMapper;
import com.alan.service.LinkService;
import com.alan.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 友链(Link)表服务实现类
 *
 * @author makejava
 * @since 2022-09-16 10:37:03
 */
@Service("linkService")
public class LinkServiceImpl
        extends ServiceImpl<LinkMapper, Link>
        implements LinkService {

    /**
     * 查询所有的审核通过的友链(Link)
     */
    @Override
    public ResponseResult getAllLink() {
        //查询所有审核通过的友链
        LambdaQueryWrapper<Link> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Link::getStatus, SystemConstants.LINK_STATUS_NORMAL);
        List<Link> linkList = list(queryWrapper);

        //转换成vo
        List<LinkVo> linkVoList
                = BeanCopyUtils.copyBeanList(linkList, LinkVo.class);
        return ResponseResult.okResult(linkVoList);
    }


}

